* Trim more uses of C date and potentially unsafe memory practices.
* Add warning fixes for garmin_xt and exif
#include "defs.h"
#include "gbfile.h" // for gbfgetdbl, gbfgetint32, gbfputint32, gbfgetint16, gbfputdbl, gbfputc, gbfread, gbfseek, gbfgetc, gbfile, gbfclose, gbfungetc, gbfeof, gbfputs, gbfwrite, gbfopen_le, gbfgetuint32, gbfputuint16, gbfputuint32
#include "jeeps/gpsmath.h" // for GPS_Lookup_Datum_Index, GPS_Math_Known_Datum_To_WGS84_C, GPS_Math_NGENToAiry1830LatLon
+#include "src/core/logging.h" // for FatalMsg
#include "xmlgeneric.h" // for cb_cdata, xg_callback, xg_string, xml_deinit, xml_init, cb_end, cb_start, xg_cb_type, xml_read, xml_readstring, xg_tag_mapping
}
-static char*
+static QString
read_str(gbfile* f)
{
int i = gbfgetc(f);
i = gbfgetint16(f);
}
- char* res = (char*) xmalloc(i + 1);
- res[i] = '\0';
- if (i) {
- gbfread(res, 1, i, f);
- }
-
- return res;
+ return gbfreadbuf(i, f);
}
static void
static int
read_datum(gbfile* f)
{
- char* d = read_str(f);
- char* g = read_str(f);
+ auto d = read_str(f);
+ auto g = read_str(f);
int res = GPS_Lookup_Datum_Index(d);
- if (*g && (strcmp(d, g) != 0)) {
- fatal(MYNAME ": Unsupported combination of datum '%s' and grid '%s'!\n",
- d, g);
+ if (d.compare(g)) {
+ fatal(FatalMsg() << MYNAME << ": Unsupported combination of datum '" << d << "' and grid '" << g << "''!\n");
}
- xfree(d);
- xfree(g);
return res;
}
/* S1 .. S9: comments, hints, jokes, aso */
for (int i = 0; i < 9; i++) {
- char* s = read_str(fin);
- xfree(s);
+ (void) read_str(fin);
}
int32_t tcount = gbfgetint32(fin);
// variants of shortname
for (int32_t i = 0; i < namect; i++) {
- char* name = read_str(fin);
- if (name && *name) {
+ auto name = read_str(fin);
+ if (!name.isEmpty()) {
switch (i) {
case 0:
wpt->description = name;
break;
}
}
- xfree(name);
}
waypt_add(wpt);
QByteArray qba(tag->count, 0);
gbfread(qba.data(), tag->count, 1, fin);
tag->data.append(qba);
- } else for (uint16_t i = 0; i < tag->count; i++) {
+ } else for (unsigned i = 0; i < tag->count; i++) {
switch (tag->type) {
case EXIF_TYPE_SHORT:
case EXIF_TYPE_SSHORT:
if (tag->size > 4) {
if BYTE_TYPE(tag->type) {
gbfwrite(tag->data.at(0).toByteArray().constData(), tag->size, 1, fout);
- } else for (uint16_t i = 0; i < tag->count; i++) {
+ } else for (unsigned i = 0; i < tag->count; i++) {
switch (tag->type) {
case EXIF_TYPE_SHORT:
case EXIF_TYPE_SSHORT:
static void
format_garmin_xt_decrypt_trk_blk(int Count, uint8_t TrackBlock[])
{
- uint8_t j = 12;
+ int j = 12;
while (j<(Count-1)) {
for (uint8_t i = j; i < Count; i++) {
TrackBlock[i] = TrackBlock[i] >> 1;
format_garmin_xt_decrypt_trk_blk(Count, TrackBlock);
// process each track point in the loaded TrackBlock
- for (uint8_t ii = 1; ii <= ((Count-1) / 12); ii++) {
+ for (auto ii = 1; ii <= ((Count-1) / 12); ii++) {
// decompose loaded track block part (track point)
format_garmin_xt_decomp_trk_blk(ii, TrackBlock, &PrevEle, &Lat, &Lon, &Time);
fread_string(gbfile* fd)
{
int len = fread_integer(fd);
-
- if (len == 0) {
- return nullptr;
- }
-
- char* val = (char*) xmalloc(len+1);
- gbfread(val, 1, len, fd);
- while (len != 0 && val[len-1] == ' ') {
- len--;
- }
- val[len] = 0;
- QString v(val);
- xfree(val);
- return v;
+ return gbfreadbuf(len, fd);
}
static void
static QString
fread_fixedstring(gbfile* fd, int len)
{
- char* val = (char*) xmalloc(len+1);
-
- gbfread(val, 1, len, fd);
- while (len != 0 && val[len-1] == ' ') {
- len--;
- }
- val[len] = 0;
- QString v(val);
- xfree(val);
-
- return v;
+ return gbfreadbuf(len, fd);
}
/* Write functions, according to specification. */
vitosmt_read()
{
route_head* rte = nullptr;
- struct tm tmStruct;
- int serial =0;
+ int serial = 0;
-
- memset(&tmStruct, 0, sizeof(tmStruct));
/*
* 24 bytes header
*/
auto* wpt_tmp = new Waypoint;
- wpt_tmp->latitude =DEG(latrad);
- wpt_tmp->longitude =DEG(lonrad);
- wpt_tmp->altitude =elev;
+ wpt_tmp->latitude = DEG(latrad);
+ wpt_tmp->longitude = DEG(lonrad);
+ wpt_tmp->altitude = elev;
- tmStruct.tm_year =timestamp[0]+100;
- tmStruct.tm_mon =timestamp[1]-1;
- tmStruct.tm_mday =timestamp[2];
- tmStruct.tm_hour =timestamp[3];
- tmStruct.tm_min =timestamp[4];
- tmStruct.tm_sec =(int)floor(seconds);
- tmStruct.tm_isdst =-1;
+ wpt_tmp->SetCreationTime(QDateTime(
+ QDate(timestamp[0] + 2000, timestamp[1], timestamp[2]),
+ QTime(timestamp[3], timestamp[4]),
+ Qt::UTC).addMSecs(lround(seconds*1000.0)));
- double usec = fmod(1000000*seconds+0.5,1000000);
- wpt_tmp->SetCreationTime(mkgmtime(&tmStruct), lround(usec/1000.0));
wpt_tmp->shortname = QString::asprintf("WP%04d", ++serial);
WAYPT_SET(wpt_tmp, speed, KNOTS_TO_MPS(speed)); /* meters per second */